package bd;

import java.sql.*;

public class BDCreator
{
  public static void main( String args[] )
  {
    Connection c = null;
    Statement stmt = null;
    try {
      Class.forName("org.sqlite.JDBC");
      c = DriverManager.getConnection("jdbc:sqlite:C:\\registro.db");
      System.out.println("BD Aberto com sucesso.");

      stmt = c.createStatement();
      
      /*
      String sql = "CREATE TABLE Eventos " +
                   "(ID INT PRIMARY KEY     NOT NULL," +
                   " NAME           TEXT    NOT NULL, " + 
                   " AGE            INT     NOT NULL, " + 
                   " ADDRESS        CHAR(50), " + 
                   " SALARY         REAL)"; 
      stmt.executeUpdate(sql);
      
      */
      
      
      
      /*
      String sql;
      sql = "DROP TABLE EVENTOS";
      stmt.executeUpdate(sql);
      
      sql =	"CREATE TABLE EVENTOS " +
      				"(VALOR	CHAR(10) NOT NULL, " +
      				"HORA   CHAR(10) NOT NULL, " +
      				"DATA   CHAR(10) NOT NULL," +
      				"TIPO   CHAR(10) NOT NULL)";
      stmt.executeUpdate(sql);
      */
      
      String sql;
      sql = "DROP TABLE USUARIOEVENTO";
      stmt.executeUpdate(sql);
      
      sql =	"CREATE TABLE USUARIOEVENTO " +
      				"(USUARIO	CHAR(30) NOT NULL, " +
      				" EVENTO    CHAR(10) NOT NULL, " +
      				" MIN       CHAR(10) NOT NULL, " +
      				" MAX       CHAR(10) NOT NULL, " +
      				" HORAATUAL CHAR(10) NOT NULL, " +
      				" DATAATUAL CHAR(10) NOT NULL) ";
      stmt.executeUpdate(sql);
      
      
      stmt.close();
      c.close();
    } catch ( Exception e ) {
      System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      System.exit(0);
    }
    System.out.println("Table created successfully");
  }
}